//牛客 HJ22 汽水瓶
#include <iostream>
using namespace std;

int cal(int n)
{
    int sum=0;
    while (n>1) {
        int res=n/3;
        int left =n%3;
        sum+=res;
        n=left+res;
        if(n==2)
        {
            ++sum;
            break;
        }
    }
    return sum;
}

int main() {
    int n,res;
    while(cin>>n)
    {
        if(n==0)
        {
            break;
        }
        res=cal(n);
        cout<<res<<endl;
    }
    return 0;
}